-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Flashloan rebalancer #112
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #112 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 22 23 +1
Lines 912 936 +24
=========================================
+ Hits 912 936 +24 ☔ View full report in Codecov by Sentry. |
function onFlashLoan( | ||
address initiator, | ||
address, | ||
uint256 amount, | ||
uint256 fee, | ||
bytes calldata data | ||
) external returns (bytes32) { | ||
if (msg.sender != address(FLASHLOAN) || initiator != address(this) || fee != 0) revert NotTrusted(); | ||
(uint256 typeAction, address collateral, address vault, uint256 minAmountOut) = abi.decode( | ||
data, | ||
(uint256, address, address, uint256) | ||
); | ||
address tokenOut; | ||
address tokenIn; | ||
if (typeAction == 1) { | ||
// Increase yield exposure action: we bring in the ERC4626 token | ||
tokenOut = collateral; | ||
tokenIn = vault; | ||
} else { | ||
// Decrease yield exposure action: we bring in the liquid asset | ||
tokenIn = collateral; | ||
tokenOut = vault; | ||
} | ||
uint256 amountOut = TRANSMUTER.swapExactInput(amount, 0, AGTOKEN, tokenOut, address(this), block.timestamp); | ||
if (typeAction == 1) { | ||
// Granting allowance with the collateral for the vault asset | ||
_adjustAllowance(collateral, vault, amountOut); | ||
amountOut = IERC4626(vault).deposit(amountOut, address(this)); | ||
} else amountOut = IERC4626(vault).redeem(amountOut, address(this), address(this)); | ||
_adjustAllowance(tokenIn, address(TRANSMUTER), amountOut); | ||
uint256 amountStableOut = TRANSMUTER.swapExactInput( | ||
amountOut, | ||
minAmountOut, | ||
tokenIn, | ||
AGTOKEN, | ||
address(this), | ||
block.timestamp | ||
); | ||
if (amount > amountStableOut) { | ||
uint256 subsidy = amount - amountStableOut; | ||
orders[tokenIn][tokenOut].subsidyBudget -= subsidy.toUint112(); | ||
budget -= subsidy; | ||
emit SubsidyPaid(tokenIn, tokenOut, subsidy); | ||
} | ||
return CALLBACK_SUCCESS; | ||
} |
Check notice
Code scanning / Slither
Block timestamp Low
Dangerous comparisons:
- amount > amountStableOut
function adjustYieldExposure( | ||
uint256 amountStablecoins, | ||
uint8 increase, | ||
address collateral, | ||
address vault, | ||
uint256 minAmountOut | ||
) external { | ||
if (!TRANSMUTER.isTrustedSeller(msg.sender)) revert NotTrusted(); | ||
FLASHLOAN.flashLoan( | ||
IERC3156FlashBorrower(address(this)), | ||
address(AGTOKEN), | ||
amountStablecoins, | ||
abi.encode(increase, collateral, vault, minAmountOut) | ||
); | ||
} |
Check warning
Code scanning / Slither
Unused return Medium
6ac380e
to
84de3b4
Compare
84de3b4
to
af908aa
Compare
No description provided.